/*******************************************************************************

  Paying Outsourced Labor: Direct Evidence from Linked Temp Agency-Worker-Client Data

  By Andres Drenik, Simon Jäger, Pascuel Plotkin and Benjamin Schoefer
	January 7th, 2021

	DESCRIPTION: Calculates the prevalence of user firms in the connected set

*******************************************************************************/




/********************************************************************************
***** Preliminaries
********************************************************************************/
set more off
cap log close
local curr_date = c(current_date)
log using "${logs}/16_User_Firms_Connected_Calculations`curr_date'", replace


/****************************************************************************************
* Load Dataset
****************************************************************************************/

use "$intermediate_data_emp/AKM_Firm_FE_for_export_stata.dta", clear

/****************************************************************************************
* Run Figures
****************************************************************************************/

*Calculate the magnitud of user firms in the connected set (firms)
sum uf_fe4 if firm_fe4 != 0 & firm_fe4 != . & uf_fe4 != 0 & uf_fe4 != . & connected_set == 1
global uf = r(N)
sum firm_fe4 if firm_fe4 != 0 & firm_fe4 != . & connected_set == 1
global reg = r(N)
global uf_firms_connected = (${uf} / ${reg})*100
display("The percentage of firms that are user frms in the connected set is: ${uf_firms_connected}")

*Calculate the prevalence of user firms in the connected set (worker month observations)
sum uf_fe4 [fw=obs] if firm_fe4 != 0 & firm_fe4 != . & uf_fe4 != 0 & uf_fe4 != . & connected_set == 1
global uf = r(N)
sum firm_fe4 [fw=obs] if firm_fe4 != 0 & firm_fe4 != . & connected_set == 1
global reg = r(N)
global uf_obs_connected = (${uf} / ${reg})*100
display("The percentage of observations that are user frms in the connected set is: ${uf_obs_connected}")

log close
